package CRUD;

// default package
// Generated Apr 21, 2011 3:13:26 PM by Hibernate Tools 3.3.0.GA

import Utility.SessionFactoryUtil;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Example;
import xmlMapping.Moderatorpermessions;
/**
 * Home object for domain model class Moderatorpermessions.
 * @see .Moderatorpermessions
 * @author Hibernate Tools
 */
public class ModeratorpermessionsHome {

	private static final Log log = LogFactory
			.getLog(ModeratorpermessionsHome.class);

      	public Session session;

    public ModeratorpermessionsHome() {
           if(session==null|| !session.isOpen())
           
        session=SessionFactoryUtil.getSessionFactory().openSession();
       
        
    }

	public void persist(Moderatorpermessions transientInstance) {
       
            session.beginTransaction();
		log.debug("persisting Moderatorpermessions instance");
		try {
			session.persist(transientInstance);
                         session.getTransaction().commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Moderatorpermessions instance) {
       
            session.beginTransaction();
		log.debug("attaching dirty Moderatorpermessions instance");
		try {
			session.saveOrUpdate(instance);
                         session.getTransaction().commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Moderatorpermessions instance) {
       
            session.beginTransaction();
            log.debug("attaching clean Moderatorpermessions instance");
		try {
			session.lock(instance, LockMode.NONE);
                         session.getTransaction().commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Moderatorpermessions persistentInstance) {
       
            session.beginTransaction();
		log.debug("deleting Moderatorpermessions instance");
		try {
			session.delete(persistentInstance);
                         session.getTransaction().commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Moderatorpermessions merge(Moderatorpermessions detachedInstance) {
       
            session.beginTransaction();
            log.debug("merging Moderatorpermessions instance");
		try {
			Moderatorpermessions result = (Moderatorpermessions) session.merge(detachedInstance);
                         session.getTransaction().commit();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Moderatorpermessions findById(int id) {
       
            session.beginTransaction();
		log.debug("getting Moderatorpermessions instance with id: " + id);
		try {
			Moderatorpermessions instance = (Moderatorpermessions) session
					.get(Moderatorpermessions.class, id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Moderatorpermessions instance) {
       
            session.beginTransaction();
		log.debug("finding Moderatorpermessions instance by example");
		try {
			List results = session.createCriteria(
					Moderatorpermessions.class).add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
